import sys
import time

from PySide6.QtCore import QTimer
from PySide6.QtWidgets import QApplication, QDialog, QLineEdit, QPushButton, QVBoxLayout


class Form(QDialog):

    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.timer = None
        self.durations = [1000, 2000, 3000, 4000, 5000]
        self.index = 0
        self.setWindowTitle("My Form")
        # Create widgets
        self.button = QPushButton("Start timer")
        # Add button signal to greetings slot
        self.button.clicked.connect(self.start_timer)
        # Create layout and add widgets
        layout = QVBoxLayout(self)
        layout.addWidget(self.button)

    def start_timer(self):
        self.timer = QTimer()
        self.timer.setInterval(self.durations[self.index])
        self.timer.timeout.connect(self.time_out)
        self.timer.start()

    def time_out(self):
        self.timer.stop()
        self.index += 1
        if self.index == len(self.durations):
            print(f"{time.ctime()} -- end")
            return
        dura = self.durations[self.index]
        print(f"{time.ctime()} -- next duration: {dura}")
        self.timer.setInterval(dura)
        self.timer.start()


if __name__ == '__main__':
    # Create the Qt Application
    app = QApplication(sys.argv)
    # Create and show the form
    form = Form()
    form.show()
    # Run the main Qt loop
    sys.exit(app.exec())
